<!DOCTYPE html>
<html>

<head lang="en">
    <title>找攻略</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategy.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <script src="/js/common.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script>

        $(function(){
            var params = getParams();
            if (params.keyword) {
                $.get('/search/strategy/' + params.keyword, function (data) {
                    console.log(data);
                });
            }


            //获取1条攻略推荐
            $.get('/travels/commends',{type:3,pageSize:1},function (data) {
                $(".commend").renderValues(data.list[0],{
                    getHref:getHref
                });

            })

            //获取所有状态为推荐的大攻略
            $.get('/strategies',{state:1,pageSize:0},function (data) {
                $(".strategyCommend").renderValues(data,{
                    getHref:getHref
                });
            })

            //全局变量,地区id
            var regionId;

            //获取状态为推荐的地区
            $.get('/regions',{state:1},function (data) {
                var temp = '';
                var content = '';
                $.each(data,function (index,ele) {
                    temp += '<li class="nav-item"><a data-id="'+ele.id+'" class="nav-link" data-toggle="pill" href="#pills-'+ele.id+'">'+ele.name+'</a></li>';
                    content += '<div class="tab-pane fade" id="pills-'+ele.id+'"></div>';
                })
                //标签头
                $("#pills-tab").append(temp);
                //内容
                $("#pills-tabContent").append(content);

                //绑定点击事件
                $(".nav-link").click(function () {
                    //获取当前点击的地区的id
                    var id = $(this).data('id');
                    //获取html的数据
                    if(id) {
                        //设置地区id
                        regionId = id;

                        //清空分页参数
                        currentInput.val(2);
                        pages = 2;

                        $.get('/regions/' + id + '/strategies', function (data) {
                            $("#pills-" + id).html(data);
                        },'html');
                    }
                })

            })

            //分页
            //当前页的input框
            var currentInput = $("#currentPage");

            //总页数
            var pages = 2;

            //获取我的游记数据
            function query() {
                //获取当前页的值
                var currentPage = currentInput.val();
                $.get('regions/'+regionId+'/strategies', {currentPage: currentPage}, function (data) {
                    var temp = '';
                    //把获取的分页数据设置到页面
                    $.each(data.list,function(index,ele){
                        temp += '<div class="col-6 mb">\n' +
                            '                <a href="../strategyCatalogs.html?strategyId='+ele.id+'">\n' +
                            '                    <img class="float-left " src="'+ele.coverUrl+'">\n' +
                            '                    <div class="classify-text">\n' +
                            '                        <span>'+ele.title+'</span>\n' +
                            '                        <p>0人收藏</p>\n' +
                            '                    </div>\n' +
                            '                </a>\n' +
                            '            </div>'
                    })

                    $('.classify').append(temp);

                    //设置总页数
                    pages = data.pages;
                },'json')
                //当前页input框+1
                currentInput.val(parseInt(currentPage) + 1);
            }


            //当页面滚动条变化时，执行的函数
            $(window).scroll(function () {
                if ($(document).scrollTop() + $(window).height() >= $(document).height()) {
                    var currentPage = currentInput.val();
                    //判断是否小于或等于最后一页,如果是就去查询
                    if (currentPage <= pages) {
                        query();
                    } else {
                        $(document).dialog({
                            type: 'notice',
                            infoText: '已经到底了!',
                            autoClose: 1000
                        });
                    }
                }
            });


            // //本页面的搜索按钮搜索功能
            $("#serachStrsategy").click(function () {
                if ($("#keyword").val() != null&&$("#keyword").val() !='') {
                    window.location.href="search.html?keyword="+$("#keyword").val()
                }
            });

        })
    </script>
</head>

<body>
<!--从第二页开始-->
<input type="hidden" name="currentPage" id="currentPage" value="2">

<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search" id="serachStrsategy">
                <input class="form-control searchBtn" placeholder="搜索旅行攻略" name="keyword" id="keyword">
            </div>
        </div>
    </div>
</div>



<div class="tab-content" id="pills-tabContent">
    <div class="tab-pane fade active show" id="pills-top">
        <div class="container commend">
            <a data-href="travelContent.html?id=" render-key="travel_id" render-fun="getHref">
                <img render-src="coverUrl">
                <p render-html="title"></p>
            </a>
        </div>

        <div class="container strategyCommend">
            <h6>当季推荐</h6>
            <div class="row hot" render-loop="list">
                <div class="col-4">
                    <a data-href="strategyCatalogs.html?strategyId=" render-key="list.id" render-fun="getHref">
                        <img render-src="list.coverUrl">
                        <p render-html="list.title"></p>
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>
</body>

</html>
